package com.xiaoye.qbproject.controller.qbzt;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xiaoye.qbproject.controller.base.BaseController;
import com.xiaoye.qbproject.domain.AjaxResult;
import com.xiaoye.qbproject.domain.SubjectZl;
import com.xiaoye.qbproject.page.TableDataInfo;
import com.xiaoye.qbproject.service.SubjectZlService;
import com.xiaoye.qbproject.vo.SubjectZlVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/subjectZl")
public class SubjectZlController extends BaseController {

    @Autowired
    private SubjectZlService subjectZlService;

    @GetMapping("/list")
    public TableDataInfo list(SubjectZlVo subjectZlVo) {
        startPage();

        List<SubjectZlVo> list = subjectZlService.getList(subjectZlVo);
        return getDataTable(list);
    }

    @PostMapping
    public AjaxResult add(@RequestBody SubjectZlVo subjectZlVo) {
        subjectZlService.add(subjectZlVo);
        return success();
    }

    @DeleteMapping
    public AjaxResult delete(@RequestBody SubjectZlVo subjectZlVo) {
        subjectZlService.remove(Wrappers.<SubjectZl>lambdaQuery()
                .eq(SubjectZl::getSubjectId, subjectZlVo.getSubjectId())
                .in(SubjectZl::getZlId, subjectZlVo.getZlIds())
        );
        return success();
    }
}
